home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / CNetDemo / cnet / sdk / Examples / DosDoor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-04  |  1.7 KB  |  59 lines

  1. /**************************************************************************
  2.  * CNet Amiga Programs and examples © 1988-1996 ZenMetal Software         *
  3.  * These examples may be freely distributed to any developer wishing      *
  4.  * to write doors for CNet Amiga.  ZenMetal retains copyright on all code *
  5.  * within these examples                                                  *
  6.  *                                                                        *
  7.  * DOSDOOR.C                                                              *
  8.  * A simple DOS DOOR to illustrate how to get input/output from users     *
  9.  **************************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <dos.h>
  15. #include <clib/dos_protos.h>
  16.  
  17. void main(int argc, char *argv[])
  18. {
  19.     BPTR inputfh=NULL;
  20.     BPTR outputfh=NULL;
  21.     char OutLine[100];
  22.     char Buffer[5];
  23.     BOOL done=FALSE;
  24.  
  25.     inputfh=Input();        /* get DOS input/output filehandles */
  26.     outputfh=Output();
  27.  
  28.     SetMode(inputfh, 1);    /* set stdio to RAW: mode */
  29.     SetMode(outputfh, 1);
  30.  
  31.     Write(outputfh, "Enter text: ", 6);
  32.     for( ; !done ; )
  33.         {
  34.         if(WaitForChar( inputfh, 5000000))    /* wait at least 5 seconds for input */
  35.             {
  36.             if(Read(inputfh, Buffer, 1))    /* WaitForChar returned non-zero - get one character from stdio */
  37.                 {
  38.                 Buffer[1] = 0;
  39.                 switch(Buffer[0])
  40.                     {
  41.                     case 27:    /* ESCape pressed - exit! */
  42.                         done=TRUE;
  43.                     default:    /* just general baloney to verify keys pressed */
  44.                         sprintf(OutLine, "\nUser Entered '%c'\n", Buffer[0]);
  45.                         Write(outputfh, OutLine, strlen(OutLine));
  46.                     }
  47.                 }
  48.             }
  49.         else
  50.             {
  51.             Write(outputfh, "\n**timeout\n", 11);
  52.             }
  53.         }
  54.  
  55.     SetMode(inputfh, 0);    /* restore state of stdio to CON: mode */
  56.     SetMode(outputfh, 0);
  57.     exit(0);
  58. }
  59.